home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
shells
/
init9akp.zoo
/
init.doc
next >
Wrap
Text File
|
1991-11-04
|
13KB
|
324 lines
This file is not an "official" part of MiNT, but please distribute it
with init.prg.
This document describes the version of the "init" shell released
11/4/91 by Allan Pratt.
-----------------------------------------------------------------------
init.prg: by Allan Pratt and Eric Smith
Here is a sample shell that can be used as init.prg for MiNT (if you like
it; there's nothing special about this shell, and any other non-GEM program
could be used, or gem.prg if you want GEM to start right away). This shell
is useful mainly for its understanding of job control.
When started, init looks in the current directory for the file "init.rc";
if this file is found, the lines in it are read and processed just as if
they had been typed at the keyboard. A prompt is then printed, and lines
are read from the keyboard until an end of file character (^D) is
encountered. Commands on a line may be separated by the ";" character (in
which case they are executed one after another), the "&" character (in
which case they are executed concurrently), or by the "|" character (in
which case they are executed concurrently with the standard output of the
first command connected to the standard input of the second command). Any
line starting with a "#" character is treated as a comment, and ignored.
External commands are searched for using the environment variable PATH,
which should consist of directories separated by commas. See the sample
init.rc for an example. Arguments are passed to external commands using the
Atari extended argument passing convention.
I/O redirection is supported for external commands; to redirect the output
of a command to a file, use "> file"; to append to a file use ">> file";
and to redirect input from a file use "< file". In addition, use ">& file"
or ">>& file" to redirect both stdout and stderr to file, and "2> file" or
"2>> file" to redirect just stderr. "prog args 2> err > out" will redirect
stderr to "err" and stdout to "out."
Command-line Arguments
============ =========
-v Causes all commands to be echoed to the screen before they're
executed. See VERBOSITY.
-s Causes batch files to be aborted if a command in the batch
file exits with nonzero $STATUS. See BATCH_EXIT.
-c args ... All args after -c are collected into a line, and that line
is executed by the shell. Then the shell exits with that
command's $STATUS code.
Variables
=========
Variables are set with setenv, and are referenced by prefixing their names
with a "$", e.g.:
echo $PATH
will echo the value of the environment variable PATH. The name may be
enclosed in parentheses or braces; thus
setenv FOO foo
echo $(FOO)bar ${FOO}bar
will echo "foobar foobar". If there are no
parentheses or braces, the name of the environment variable ends with the
first character not in the set [A-Za-z0-9_?*], so "echo $FOO\bar" yields
"foo\bar" and "echo $FOO*" does not yield files matching "foo*" but rather
the value of the variable 'FOO*'.
Typing "setenv" with no arguments will show the values of all environment
variables.
The following variables have special meaning to the shell:
$PATH: as mentioned above, is used to find programs. Setting this
causes an automatic "rehash" (see below).
$PROMPT: printed before each line of input in an interactive shell.
$BATCH_EXIT: the value of this variable should be a number. When
nonzero, batch files (and even the shell itself) will exit when any
command returns a nonzero exit code.
$VERBOSITY: when nonzero, all commands are displayed on the screen
after being alias-expanded, wildcard-expanded, and
variable-substituted, but before being executed.
$NOTIFY: when nonzero, a message will be printed on your screen as
soon as a background job exits, rather than waiting until the next
time the shell prompt is printed.
In addition, the following things can be used like environment variables,
but they are not truly in your environment:
$CWD: yields your current working directory.
$STATUS: yields the exit code of the last command or batch file.
(the exit code of a batch file is the exit code of the last command
executed from that batch file.)
If you use $ for variable-substitution on the command line and there is no
variable with the name you give, an error message is printed and the
command is not run.
Wildcards
=========
It is possible to refer to a group of files with similar names by means of
special characters ("wildcards"). For example, the pattern "*.c" means "all
files that have the extension .c". Thus, if the current directory contains
the files "foo", "foo.c", "bar.c", and "bar.doc", the command
echo *.c
would be exactly equivalent to
echo foo.c bar.c
and
echo *c
would be the same as
echo foo.c bar.c bar.doc
(Note that the files appear in their "true" order on the disk, not necessarily
in alphabetical order).
The following wildcards are supported:
*: matches any sequence of 0 or more characters
?: matches any 1 character
[...]: matches one character inside the brackets; if two characters are
seperated by a minus sign ('-') then all characters between those
two are also matched
Examples:
[ad-gz]* matches all files beginning with 'a', 'd', 'e', 'f', 'g', or
'z' (read as "(a, or d through g, or z) followed by anything").
*.* matches all files containing a period. Note the difference
from some wildcard matching, in which '*.*' matches ALL files.
a*.[ch] matches all files starting with 'a' and having an extension
of '.c' or '.h'.
If you have any wildcards in a command line, and none of them actually
matches any files, an error message is printed and the command is not run.
Batch Files
===========
Init commands may be placed in a file with a ".bat" extension; typing the
filename (with or without the ".bat" extension) will then run those
commands.
Arguments to batch files are accessed in a way similar to environment
variables: $1 yields the first argument to the batch file, $2 the second,
and so on. $0 yields the name of the batch file itself, $* yields all
arguments from $1 on, $? yields the number of arguments, and the built-in
command 'shift' shifts $3 to $2, $2 to $1, and so on, and decrements $?.
'shift' leaves $0 alone. Example of a simple batch file which executes the
command named in its first argument, giving it the string "fixed_args" as
its first argument and the rest of the batch-file command line as the rest
of its args:
echo This is batch file $0, which will execute the command $1.
setenv cmdHOLD $1
shift
$cmdHOLD fixed_args $*
Batch file arguments do nest, but each one is executed by the same shell,
with the same environment and so on, so they can affect the global shell
state (i.e. current directory, environment, aliases, etc.). This is a lose
and should be re-done. In the meantime, if you want to execute a batch
file in its own shell, use "init -c batch_file_name batch_file_args ..."
[Note to shell hackers: the ability to use $? relies on dollar substitution
being done before wildcard substitution, because ? is a wildcard character.
Also, the ability to use $? (and $STATUS) is useless without an "if"
command.]
Version note: arguments to batch files are new as of 2/91.
Grubby details department: if a string starting with a digit gets to dollar
substitution, atoi is called on it and that's what you get. The
substitution for $1one is the first argument to the batch file, not
getenv("1one"). If there is no Nth argument you get an error message.
Builtin Commands
================
The following commands are built in:
alias [string [command]]
With no arguments, prints a list of all aliases.
With one argument, shows what command the given string is aliased to.
With two or more arguments, the first argument ("string") becomes an
alias for the command consisting of all the other arguments. After this,
typing "string" is the same as typing that command.
Example:
alias c d:\bin\gcc.ttp -O -c
c